package com.swust.exam.controller;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;


import org.springframework.web.bind.annotation.RequestMapping;


import com.swust.exam.pojo.Classes;
import com.swust.exam.service.ClassesService;



@Controller
@RequestMapping("/classes")
public class ClassesController {
	@Autowired
	private ClassesService classesService;
	
	
	@RequestMapping(value = "/get")
	public String classesGet(String semester,Model model)
	{
		
		
		 return "classes";
	}
	
	
	@RequestMapping(value="/delete")
	public String classesDelete(Integer id,Model model) {
		classesService.delete(id);
		List<Classes> list=classesService.classeslist();
		model.addAttribute("classeslist",list);
		List<Classes> list2=classesService.courselist();
		 model.addAttribute("courselist",list2);
		 List<Classes> list3=classesService.teacherslist();
		 model.addAttribute("teacherslist",list3);
	
		return "classes";
	}
	
	@RequestMapping(value="/insert")
	public String classesInsert(Classes classes,Model model) {
		 classesService.insertCourseIdAndteacherId(classes);
		 List<Classes> list=classesService.classeslist();
		 model.addAttribute("classeslist",list);
		 List<Classes> list2=classesService.courselist();
		 model.addAttribute("courselist",list2);
		 List<Classes> list3=classesService.teacherslist();
		 model.addAttribute("teacherslist",list3);
		
		return "classes";
	}
	
	@RequestMapping(value="/update")
	public String classesUpdate(Classes classes,Model model) {
		classesService.updateByclassIdAndteacherId(classes);
		List<Classes> list=classesService.classeslist();
		 model.addAttribute("classeslist",list);
		 List<Classes> list2=classesService.courselist();
		 model.addAttribute("courselist",list2);
		 List<Classes> list3=classesService.teacherslist();
		 model.addAttribute("teacherslist",list3);
		
		return "classes";
	}

}
